package com.atguigu.gmall.server;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.entiity.DAUPerHour;
import com.atguigu.gmall.entiity.GMVPerHour;
import com.atguigu.gmall.mapper.DauMapper;
import com.atguigu.gmall.mapper.ESMapper;
import com.atguigu.gmall.mapper.GmvMapper;
import io.searchbox.core.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * @ClassName: PublisherServiceImpl
 * @Description:
 * @Author: kele
 * @Date: 2021/3/19 20:45
 **/

@Service
public class PublisherServiceImpl implements PublisherService{

    @Autowired
    private DauMapper dauMapper;

    @Autowired
    private GmvMapper gmvMapper;

    @Autowired
    private ESMapper esMapper;

    @Override
    public Integer getDAUbyDate(String date) {
        return dauMapper.getDAUbyDate(date);
    }

    @Override
    public Integer getMidCountbyDate(String date) {

        return dauMapper.getMidCountbyDate(date);

    }

    @Override
    public List<DAUPerHour> getMidCountByHour(String date) {

        return dauMapper.getMidCountByHour(date);
    }

    @Override
    public Double getGMVbyDate(String date) {
        return gmvMapper.getGMVbyDate(date);
    }

    @Override
    public List<GMVPerHour> getGMVSumByHour(String date) {
        return gmvMapper.getGMVSumByHour(date);
    }

    @Override
    public JSONObject getAnalysis(String date, Integer startpage, Integer size, String keyword) throws IOException {

        SearchResult searchResult = esMapper.getData(date, startpage, size, keyword);

        JSONObject jsonObject = esMapper.parseResult(searchResult);

        return jsonObject;

    }


}
